home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / games / nhak_src.zip / LEV_MAIN.C < prev    next >
C/C++ Source or Header  |  1993-03-16  |  4KB  |  179 lines

  1. /*    SCCS Id: @(#)lev_main.c    3.0    89/07/02
  2. /*    Copyright (c) 1989 by Jean-Christophe Collet */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /*
  6.  * This file contains the main function for the parser
  7.  * and some useful functions needed by yacc
  8.  */
  9.  
  10. /* #include "hack.h"    /* uncomment for the Mac */
  11.  
  12. #ifndef VMS
  13. # if defined(AMIGA) || defined(MSDOS)
  14. #  include "hack.h"
  15. #  undef exit
  16. #  ifdef MSDOS
  17. extern void FDECL(exit, (int));
  18. #  endif
  19. # else
  20. #  include <stdio.h>
  21. # endif
  22. #else  /*VMS*/
  23. # ifdef ANCIENT_VAXC    /* need KR1ED setup */
  24. #  define GLOBAL_H      /* don't need other stuff */
  25. #include "config.h"
  26. # endif
  27. #include <stdio.h>
  28. # define exit vms_exit
  29. #endif /*VMS*/
  30.  
  31. #define MAX_ERRORS    25
  32.  
  33. extern int line_number;
  34. char *fname = "(stdin)";
  35. int fatal_error = 0;
  36.  
  37. #ifdef LATTICE
  38. long *alloc(unsigned int);
  39. #ifdef exit
  40. #undef exit
  41. #endif
  42. #include <stdlib.h>
  43. #endif
  44.  
  45. #ifdef    FDECL
  46. int  FDECL (main, (int, char **));
  47. int  NDECL (yyparse);
  48. void FDECL (yyerror, (char *));
  49. void FDECL (yywarning, (char *));
  50. int  NDECL (yywrap);
  51. #endif
  52.  
  53. #ifdef LSC
  54. _main(argc, argv)
  55. #else
  56. main(argc, argv) 
  57. #endif
  58. int argc;
  59. char **argv;
  60. {
  61.     FILE *fin;
  62.     int i;
  63.  
  64. #if defined(MACOS) && defined(SMALLDATA)
  65. # ifdef THINKC4
  66. #include <console.h>
  67. # endif
  68. #define YYLMAX    2048
  69.     extern char    *yysbuf, *yytext, *yysptr;
  70.     Handle temp;
  71.     Str255 name;
  72.     long    j;
  73.     extern struct permonst *mons;
  74.     extern struct objclass *objects;
  75.     char descrip[3][32];    /* 3 special level description files */
  76.  
  77.     /* sub in the Nethack resource filename */
  78.     Strcpy((char *)name, "\021nethack.proj.rsrc");
  79.     yysbuf = (char *)alloc(YYLMAX);
  80.     yysptr = yysbuf;
  81.     yytext = (char *)alloc(YYLMAX);
  82.  
  83.     (void)OpenResFile(name);
  84.     temp = GetResource(HACK_DATA, MONST_DATA);
  85.     if (temp) {
  86.         DetachResource(temp);
  87.         MoveHHi(temp);
  88.         HLock(temp);
  89.         i = GetHandleSize(temp);
  90.         mons = (struct permonst *)(*temp);
  91.     } else {
  92.         panic("Can't get MONST resource data.");
  93.     }
  94.     
  95.     temp = GetResource(HACK_DATA, OBJECT_DATA);
  96.     if (temp) {
  97.         DetachResource(temp);
  98.         MoveHHi(temp);
  99.         HLock(temp);
  100.         i = GetHandleSize(temp);
  101.         objects = (struct objclass *)(*temp);
  102.         for (j = 0; j< NROFOBJECTS+1; j++) {
  103.             objects[j].oc_name = sm_obj[j].oc_name;
  104.             objects[j].oc_descr = sm_obj[j].oc_descr;
  105.         }
  106.     } else {
  107.         panic("Can't get OBJECT resource data.");
  108.     }
  109.     Sprintf(descrip[1], "%s", ":auxil:castle.des");
  110.     Sprintf(descrip[2], "%s", ":auxil:endgame.des");
  111.     Sprintf(descrip[3], "%s", ":auxil:tower.des");
  112.     argc = 4;    /* argv[0] is irrelevant, argv[i] = descrip[i] */
  113. #else   /* !MACOS || !SMALLDATA */
  114. # ifdef VMS
  115.     extern FILE *yyin, *yyout;
  116.     yyin = stdin,  yyout = stdout;
  117. # endif
  118. #endif
  119.  
  120.     if (argc == 1)        /* Read standard input */
  121.         yyparse();
  122.     else             /* Otherwise every argument is a filename */
  123.         for(i=1; i<argc; i++) {
  124. #ifdef MACOS
  125.                     argv[i] = descrip[i];
  126.                     fprintf(stdout, "Working on %s\n", argv[i]);
  127. #endif
  128. #if defined(AZTEC_C)
  129.             extern FILE *yyin;
  130.             yyin = fin = fopen(argv[i], "r");
  131. #else
  132.             fin = freopen(argv[i], "r", stdin);
  133. #endif
  134.             fname = argv[i];
  135.             if (!fin) 
  136.             fprintf(stderr,"Can't open %s\n", argv[i]);
  137.             else
  138.             yyparse();
  139.             line_number = 1;
  140.             fatal_error = 0;
  141.         }
  142. #ifndef VMS
  143.     return 0;
  144. #else
  145.     return 1;       /* vms success */
  146. #endif /*VMS*/
  147. }
  148.  
  149. /* 
  150.  * Each time the parser detects an error, it uses this function.
  151.  * Here we take count of the errors. To continue farther than
  152.  * MAX_ERRORS wouldn't be reasonable.
  153.  */
  154.  
  155. void yyerror(s)
  156. char *s;
  157. {
  158.     fprintf(stderr,"%s : line %d : %s\n",fname,line_number, s);
  159.     if (++fatal_error > MAX_ERRORS) {
  160.         fprintf(stderr,"Too many errors, good bye!\n");
  161.         exit(1);
  162.     }
  163. }
  164.  
  165. /* 
  166.  * Just display a warning (that is : a non fatal error)
  167.  */
  168.  
  169. void yywarning(s)
  170. char *s;
  171. {
  172.     fprintf(stderr,"%s : line %d : WARNING : %s\n",fname,line_number,s);
  173. }
  174.  
  175. yywrap()
  176. {
  177.        return 1;
  178. }
  179.